#提交数据
import requests

def submit_data(device_id, serial_data):
    # 将字节数据转换为16进制字符串
    hex_serial_data = serial_data.hex()
    url = f'http://localhost:5800/upload_data/{device_id}'
    response = requests.post(url, data={'serial_data': hex_serial_data})
    print(response.status_code)
    return response.json()

# 示例调用
device_id = 1
serial_data = b'Hello, World!'  # 假设这是你要发送的字节数据
result = submit_data(device_id, serial_data)
print(result)




#下载数据
import requests

def download_data(device_id, reset_queue=False):
    url = f'http://localhost:5800/get_data_rst/{device_id}' if reset_queue else f'http://localhost:5800/get_data/{device_id}'
    response = requests.get(url)
    print(response.status_code)
    if response.status_code == 200:
        data = response.json()
        # 将16进制字符串转换回字节数据
        byte_data = [bytes.fromhex(d[1]) for d in data]
        return byte_data
    else:
        return response.json()

# 示例调用
device_id = 1
data = download_data(device_id, reset_queue=True)
print(data)




#提交命令
import requests

def submit_command(device_id, comd_data):
    url = f'http://localhost:5800/upload_comd/{device_id}'
    response = requests.post(url, data={'comd_data': comd_data})
    print(response.status_code)
    return response.json()

# 示例调用
device_id = 1
comd_data = 'start_capture'  # 假设这是你要发送的命令
result = submit_command(device_id, comd_data)
print(result)




#下载命令
import requests

def download_command(device_id, reset_queue=False):
    url = f'http://localhost:5800/get_comd_rst/{device_id}' if reset_queue else f'http://localhost:5800/get_comd/{device_id}'
    response = requests.get(url)
    print(response.status_code)
    return response.json()

# 示例调用
device_id = 1
comd = download_command(device_id, reset_queue=True)
print(comd)
